package com.useeinfo.oa.modules.inspection.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.inspection.enums.InsOrderOperationEnum;
import com.useeinfo.oa.modules.security.entity.SystemUser;

import javax.persistence.*;

@Entity
@Table(name = "inspection_order_log")
public class InspectionOrderLog extends SuperClassEntity<InspectionOrderLog> {
    /**
     * 操作人
     */
    @ManyToOne
    @JoinColumn(name = "user_id")
    private SystemUser systemUser;

    /**
     * 操作人姓名
     */
    private String userName;

    /**
     * 详情
     */
    private String detail;

    /**
     * 操作
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "order_operation")
    private InsOrderOperationEnum orderOperationEnum;

    /**
     * 维保单
     */
    @ManyToOne
    @JoinColumn(name = "maintain_order_id")
    private InspectionOrder inspectionOrder;

    /**
     * 关联企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public InsOrderOperationEnum getOrderOperationEnum() {
        return orderOperationEnum;
    }

    public void setOrderOperationEnum(InsOrderOperationEnum orderOperationEnum) {
        this.orderOperationEnum = orderOperationEnum;
    }

    public InspectionOrder getInspectionOrder() {
        return inspectionOrder;
    }

    public void setInspectionOrder(InspectionOrder inspectionOrder) {
        this.inspectionOrder = inspectionOrder;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("orderOperationEnum", StringConverters.null2String(getOrderOperationEnum().getName()));
        jsonObject.put("inspectionOrder", StringConverters.null2String(getInspectionOrder().getOrderName()));
        jsonObject.put("userName", StringConverters.null2String(getUserName()));
        jsonObject.put("enterprise", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        jsonObject.put("createDate", DateTimeUtils.formatDateToStringWithTime(getCreateDate()));
        jsonObject.put("detail", StringConverters.null2String(getDetail()));
        return jsonObject;
    }
}
